import os

# 定义目录和输出文件路径
data_dir = "./01-exercise/01-20/many_texts"
output_file = "./01-exercise/01-20/many_texts.txt"

# 用于存储所有文本内容
contents = []

# 遍历目录中的文件
for file in os.listdir(data_dir):
    file_path = os.path.join(data_dir, file)
    # 判断是否为文件且以 .txt 结尾
    if os.path.isfile(file_path) and file.endswith(".txt"):
        with open(file_path, 'r', encoding='utf-8') as fin:
            contents.append(fin.read())

# 用换行符连接所有内容
final_content = "\n".join(contents)

# 写入输出文件
with open(output_file, 'w', encoding='utf-8') as fout:
    fout.write(final_content)